package com.aaa.service.impl;

import com.aaa.dao.ViewTestResultSasDao;
import com.aaa.entity.ViewTestResultSas;
import com.aaa.service.ViewTestResultSasService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultFpa)表服务实现类
 *
 * @author
 * @since 2022-07-08 10:00:04
 */
@Service("viewTestResultSasService")
public class ViewTestResultSasServiceImpl implements ViewTestResultSasService {
    @Resource
    private ViewTestResultSasDao viewTestResultSasDao;

    /**
     * 分页查询
     *
     * @param viewTestResultSas 筛选条件
     * @param pageRequest       分页对象
     * @return 查询结果
     */
    @Override
    public Page<ViewTestResultSas> queryByPage(ViewTestResultSas viewTestResultSas, PageRequest pageRequest) {
        long total = this.viewTestResultSasDao.count(viewTestResultSas);
        return new PageImpl<>(this.viewTestResultSasDao.queryAllByLimit(viewTestResultSas, pageRequest), pageRequest, total);
    }

    /**
     * @param viewTestResultSas
     * @return Map
     * @create by: feng (zhaixing@163.com)
     * @description: 根据id查询对应信息
     * @create time: 2022/7/15 15:46
     */
    @Override
    public ViewTestResultSas queryRequestById(ViewTestResultSas viewTestResultSas) {
        ViewTestResultSas Result = this.viewTestResultSasDao.queryResultFpaById(viewTestResultSas);
        return Result;
    }

    /**
     * @param
     * @return Map<String, Integer>
     * @create by: feng (zhaixing@163.com)
     * @description: 查询所有数据
     * @create time: 2022/7/15 16:14
     */
    @Override
    public Map<String, Integer> queryAllPlanSas() {
        int normal = 0;
        int mild = 0;
        int moderate = 0;
        int severe = 0;
        List<ViewTestResultSas> viewSass = this.viewTestResultSasDao.queryAllPlanSas();
        for (ViewTestResultSas viewSas : viewSass) {
            double forward = viewSas.getForward();
            double inversion = viewSas.getInversion();
            double sum = (forward + inversion) * 1.25;
            if (sum <= 50) {
                normal++;
            } else if (sum >= 50 && sum <= 59) {
                mild++;
            } else if (sum >= 60 && sum <= 69) {
                moderate++;
            } else {
                severe++;
            }
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("normal", normal);
        map.put("mild", mild);
        map.put("moderate", moderate);
        map.put("severe", severe);
        return map;
    }

    /**
     * @param
     * @return java.util.List<com.aaa.entity.ViewTestResultSas>
     * @create by: feng (zhaixing@163.com)
     * @description:查询所有数据
     * @create time: 2022/7/19 21:06
     */
    @Override
    public List<ViewTestResultSas> queryAllResultSas() {
        List<ViewTestResultSas> viewTestResultSas = this.viewTestResultSasDao.queryAllResultPlanSas();
        return viewTestResultSas;
    }
    /**
     * @create by: feng (zhaixing@163.com)
     * @description: 删除
     * @create time: 2022/7/22 20:09
     * @param testId
     * @return
     */
    @Override
    public boolean deleteResultById(String testId) {
        Integer integer = this.viewTestResultSasDao.delResultSas(testId);
        if (integer>0){
            return true;
        }
        return false;
    }

}
